package com.mjlf.spring.scope;

import com.mjlf.spring.entity.TestScope;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

/**
 * @ClassName MyScope
 * @auther mjlf
 * @Date 2019/7/31 10:01
 * @Description 自定义作用域
 */
public class MyScope implements Scope {
    private static class SingleScope{
        private static TestScope testScope = new TestScope();
    }

    private static enum SingleEnum{
        INSTANCE(new TestScope());
        public TestScope testScope;

        SingleEnum(TestScope testScope) {
            this.testScope = testScope;
        }

        public TestScope getInstace(){
            return INSTANCE.testScope;
        }
    }

    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        return SingleEnum.INSTANCE.getInstace();
    }

    @Override
    public Object remove(String name) {
        return null;
    }

    @Override
    public void registerDestructionCallback(String name, Runnable callback) {

    }

    @Override
    public Object resolveContextualObject(String key) {
        return null;
    }

    @Override
    public String getConversationId() {
        return null;
    }
}
